#define  _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

#include <stack>
#include <vector>

void getResArray(stack<int>& st, vector<int>& arr, vector<vector<int>>& res) {
    for (int i = 0; i < arr.size(); i++) {
        // 入栈前检查是否出栈
        while (!st.empty() && arr[i] < arr[st.top()]) {
            int index = st.top();
            st.pop();

            if (st.empty()) {
                res[index] = { -1, i };
            }
            else res[index] = { st.top(), i };
        }
        st.push(i);
    }
    // 处理栈内剩余元素
    while (!st.empty()) {
        int index = st.top();
        st.pop();

        if (st.empty()) {
            res[index] = { -1, -1 };
        }
        else res[index] = { st.top(), -1 };
    }
}

int main() {
    int n;
    cin >> n;

    vector<vector<int>> res;
    res.resize(n);

    stack<int> st;
    vector<int> arr;
    while (n--) {
        int x;
        cin >> x;
        arr.push_back(x);
    }

    getResArray(st, arr, res);

    for (const auto& arr : res) {
        for (const auto& e : arr) {
            cout << e << " ";
        }
        cout << endl;
    }

    return 0;
}